﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ds.DataBase.Model.PersonalAssess;

namespace Domain.RealiZation
{
    public class Mapping
    {
        public static PersonalMain ToPersonalMain(PersonalMain data)
        {
            PersonalMain model = new PersonalMain();
            model.sssj = data.sssj;
            model.state = data.state;
            model.pmid = data.pmid;
            model.cjsj = data.cjsj;
            model.mobanid = data.mobanid;
            model.tableName = data.tableName;
            model.ssrid = data.ssrid;
            model.PersonalWorkSummary = new PersonalWorkSummary();
            if (data.PersonalWorkSummary != null)
            {
                model.PersonalWorkSummary.cjsj = data.PersonalWorkSummary.cjsj;
                model.PersonalWorkSummary.wsid = data.PersonalWorkSummary.wsid;
                model.PersonalWorkSummary.zjmc = data.PersonalWorkSummary.zjmc;
                model.PersonalWorkSummary.WorkSummaryItems = new List<WorkSummaryItem>();
                if (data.PersonalWorkSummary.WorkSummaryItems != null)
                {
                    foreach (var item in data.PersonalWorkSummary.WorkSummaryItems)
                    {
                        WorkSummaryItem wi = new WorkSummaryItem();
                        wi.cjsj = item.cjsj;
                        wi.wsiid = item.wsiid;
                        wi.zjlx = item.zjlx;
                        wi.zjnr = item.zjnr;
                        model.PersonalWorkSummary.WorkSummaryItems.Add(wi);
                    }
                }

            }
            model.StateLog = new List<PersonalMainStateLog>();
            foreach (var item in data.StateLog)
            {
                PersonalMainStateLog pmsl = new PersonalMainStateLog();
                pmsl.cjrid = item.cjrid;
                pmsl.cjsj = item.cjsj;
                pmsl.id = item.id;
                pmsl.isread = item.isread;
                pmsl.PersonalState = item.PersonalState;
                pmsl.msg = item.msg;
                model.StateLog.Add(pmsl);
            }
            model.AdditionalItems = new List<AdditionalItems>();
            foreach (var item in data.AdditionalItems)
            {
                AdditionalItems ai = new AdditionalItems();
                ai.cjrid = item.cjrid;
                ai.cjsj = item.cjsj;
                ai.fjxid = item.fjxid;
                ai.xmfz = item.xmfz;
                ai.xmid = item.xmid;
                ai.xmmc = item.xmmc;
                model.AdditionalItems.Add(ai);
            }
            model.PersonalPath = new List<PersonalPath>();
            foreach (var item in data.PersonalPath)
            {
                PersonalPath pp = new PersonalPath();
                pp.ControlID = item.ControlID;
                pp.fenzhi = item.fenzhi;
                pp.isEdit = item.isEdit;
                pp.isinclude = item.isinclude;
                pp.ljmc = item.ljmc;
                pp.mpid = item.mpid;
                pp.paths = item.paths;
                pp.ppid = item.ppid;
                pp.shunxu = item.shunxu;
                pp.sonmobanfenzhi = item.sonmobanfenzhi;
                pp.sonmobanid = item.sonmobanid;
                pp.PersonalContents = new List<PersonalContent>();
                foreach (var item2 in item.PersonalContents)
                {
                    PersonalContent pc = new PersonalContent();
                    pc.fenzhi = item2.fenzhi;
                    pc.shunxu = item.shunxu;
                    pc.gzcdrid = item2.gzcdrid;
                    pc.cjrid = item2.cjrid;
                    pc.cjsj = item2.cjsj;
                    pc.isedit = item2.isedit;
                    pc.iswc = item2.iswc;
                    pc.jssj = item2.jssj;
                    pc.kssj = item2.kssj;
                    pc.laiyuan = item2.laiyuan;
                    pc.ljcs = item2.ljcs;
                    pc.nr = item2.nr;
                    pc.pcid = item2.pcid;
                    pc.wcqk = item2.wcqk;
                    pc.zhou = item2.zhou;
                    pc.zpf = item2.zpf;
                    pc.PersonalEnclosures = new List<PersonalEnclosure>();
                    foreach (var item3 in item2.PersonalEnclosures)
                    {
                        PersonalEnclosure pe = new PersonalEnclosure();
                        pe.content = item3.content;
                        pe.fileHash = item3.fileHash;
                        pe.fileguid = item3.fileguid;
                        pe.path = item3.path;
                        pe.fjid = item3.fjid;
                        pe.fjmc = item3.fjmc;
                        pc.PersonalEnclosures.Add(pe);
                    }
                    pc.PersonalEvaluates = new List<PersonalEvaluate>();
                    foreach (var item3 in item2.PersonalEvaluates)
                    {
                        PersonalEvaluate pe = new PersonalEvaluate();
                        pe.cjsj = item3.cjsj;
                        pe.fz = item3.fz;
                        pe.pjrid = item3.pjrid;
                        pe.iseffective = item3.iseffective;
                        pe.pjid = item3.pjid;
                        pc.PersonalEvaluates.Add(pe);
                    }

                    if (item2.PersonalOrigin != null && item2.PersonalOrigin.pmid > 0)
                    {
                        pc.PersonalOrigin = new PersonalOrigin();
                        pc.PersonalOrigin.lyxingming = item2.PersonalOrigin.lyxingming;
                        pc.PersonalOrigin.pcid = item2.PersonalOrigin.pcid;
                        pc.PersonalOrigin.pmid = item2.PersonalOrigin.pmid;
                    }
                    pc.RelevantWorks = new List<RelevantWork>();
                    foreach (var item3 in item2.RelevantWorks)
                    {
                        RelevantWork rw = new RelevantWork();
                        rw.pcid = item3.pcid;
                        rw.xggzid = item3.xggzid;
                        pc.RelevantWorks.Add(rw);
                    }
                    pc.PersonalAnswers = new List<PersonalAnswer>();
                    foreach (var item3 in item2.PersonalAnswers)
                    {
                        PersonalAnswer pa = new PersonalAnswer();
                        pa.fenzhi = item3.fenzhi;
                        item3.html = item3.html.Replace("valueattr", "value=" + item3.fenzhi);
                        item3.html = item3.html.Replace("nameattr", "name=" + item2.pcid);
                        pa.html = item3.html;
                        pa.paid = item3.paid;
                        pa.shunxu = item3.shunxu;
                        pa.tips = item3.tips;
                        pc.PersonalAnswers.Add(pa);
                    }
                    pp.PersonalContents.Add(pc);
                }
                model.PersonalPath.Add(pp);
            }
            return model;
        }
    }
}
